﻿@model SCS.Common.Models.Teacher

@{
    SCS.Business.MembershipService _membershipServices = new SCS.Business.MembershipService();
    string userName = User.Identity.Name;
    var user = _membershipServices.GetUser(userName);
    if (user != null)
    {
        if (user.MembershipRoles.FirstOrDefault().roleID == 1)
        {
            Layout = null;
        }
        else
        {
            ViewBag.Title = "Tạo giáo viên";
            Layout = "~/Views/Shared/_TeacherLayout.cshtml";
        }
    }
}
<script src="@Url.Content("~/Scripts/jquery.validate.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.validate.unobtrusive.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.unobtrusive-ajax.min.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/jquery.ui.datepicker-vi-VN.js")" type="text/javascript"></script>
<script>
    $(function () {
        $.validator.addMethod('date',
        function (value, element) {
            if (this.optional(element)) {
                return true;
            }
            var ok = true;
            try {
                $.datepicker.parseDate('dd/mm/yy', value);
            }
            catch (err) {
                ok = false;
            }
            return ok;
        });
        $(".datefield").datepicker({ dateFormat: 'dd/mm/yy', yearRange: '1950:2020', changeYear: true, changeMonth: true });
    });
</script>
@if (user != null)
{
    if (user.MembershipRoles.FirstOrDefault().roleID == 1)
    {
        using (Html.BeginForm())
        {
    <fieldset>
        <legend>Giáo viên</legend>
        @Html.ValidationSummary(true)
        <div class="editor-label">
            @Html.Label("Tên giáo viên")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.teacherName)
            <br />
            @Html.ValidationMessageFor(model => model.teacherName)
        </div>
        <div class="editor-label">
            @Html.Label("Ngày sinh")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.dateOfBirth)
            <br />
            @Html.ValidationMessageFor(model => model.dateOfBirth)
        </div>
        <div class="editor-label">
            @Html.Label("Giới tính")
        </div>
        <div class="editor-field">
            @Html.DropDownListFor(model => model.gender, (IEnumerable<SelectListItem>)ViewBag.Genders)
            @Html.ValidationMessageFor(model => model.gender)
        </div>
        <div class="editor-label">
            @Html.Label("Địa chỉ giáo viên")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.address)
            @Html.ValidationMessageFor(model => model.address)
        </div>
        <div class="editor-label">
            @Html.Label("Số điện thoại")
        </div>
        <div class="editor-field">
            @Html.EditorFor(model => model.mobile)
            @Html.ValidationMessageFor(model => model.mobile)
        </div>
        <br />
    </fieldset>
    <div style="float: left">
        <button type="submit" id="btnUpdate" name="Command" value="Add" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only">
            <span class="ui-button-text">Tạo</span></button>
        &nbsp; &nbsp;
    </div>
        }
    }
    else
    {
    <div id="page-heading">
        <h1>Quản lý giáo viên</h1>
    </div>
    <div class="container">
        <div class="row">
            <div class="col-sm-12">
                <div class="panel panel-primary">
                    <div class="panel-heading">
                        <h4>Tạo giáo viên</h4>
                    </div>
                    <div class="panel-body">
                        @using (Html.BeginForm("AddTeacher", "Teacher", FormMethod.Post, new { @class = "form-horizontal" }))
                        {
                            @Html.ValidationSummary(true)
           
                            <div class="form-group">
                                @Html.Label("Tên giáo viên", new { @class = "col-sm-3 control-label" })
                                <div class="col-sm-6">
                                    @Html.EditorFor(model => model.teacherName, new { @class = "form-control" })
                                </div>
                                <div class="col-sm-3">
                                    @Html.ValidationMessageFor(model => model.teacherName)
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.Label("Ngày sinh", new { @class = "col-sm-3 control-label" })
                                <div class="col-sm-6">
                                    @Html.EditorFor(model => model.dateOfBirth, new { @class = "form-control" })
                                </div>
                                <div class="col-sm-3">
                                    @Html.ValidationMessageFor(model => model.dateOfBirth)
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.Label("Giới tính", new { @class = "col-sm-3 control-label" })
                                <div class="col-sm-6">
                                    @Html.DropDownListFor(model => model.gender, (IEnumerable<SelectListItem>)ViewBag.Genders, new { @class = "form-control" })
                                </div>
                                <div class="col-sm-3">
                                    @Html.ValidationMessageFor(model => model.gender)
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.Label("Địa chỉ giáo viên", new { @class = "col-sm-3 control-label" })
                                <div class="col-sm-6">
                                    @Html.EditorFor(model => model.address, new { @class = "form-control" })
                                </div>
                                <div class="col-sm-3">
                                    @Html.ValidationMessageFor(model => model.address)
                                </div>
                            </div>
                            <div class="form-group">
                                @Html.Label("Số điện thoại", new { @class = "col-sm-3 control-label" })
                                <div class="col-sm-6">
                                    @Html.EditorFor(model => model.mobile, new { @class = "form-control" })
                                </div>
                                <div class="col-sm-3">
                                    @Html.ValidationMessageFor(model => model.mobile)
                                </div>
                            </div>
                            <br />
                            <div class="row">
                                <div class="col-sm-6 col-sm-offset-3">
                                    <div class="btn-toolbar">
                                        <button class="btn-primary btn" type="submit">Tạo</button>
                                    </div>
                                </div>
                            </div>
                            <div style="color: Green; font-weight: bold">
                                @TempData["msg"]
                            </div>
                        }
                    </div>
                </div>
            </div>
        </div>
    </div>
    }
}